package com.gxar.quick.ar.server.base.controller;

import com.gxar.common.entity.PageResult;
import com.gxar.common.entity.Result;
import com.gxar.common.entity.login.LoginUserThread;
import com.gxar.common.entity.login.UserProfile;
import com.gxar.quick.ar.server.base.model.plaza.vo.request.AdminPublishPlazaRequest;
import com.gxar.quick.ar.server.base.model.plaza.vo.request.AdminUpdatePlazaRequest;
import com.gxar.quick.ar.server.base.model.plaza.vo.response.*;
import com.gxar.quick.ar.server.db.service.PlazaService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * @author linsy
 * @version 1.0
 * @created 2024/1/22 13:48
 */
@Api(tags = "管理端广场接口")
@RestController
@RequestMapping("/admin/api/plazas")
@RequiredArgsConstructor
@Slf4j
public class AdminPlazaController {

    private final PlazaService plazaService;

    @ApiOperation("发布广场内容")
    @PostMapping("")
    public Result<AdminPublishPlazaResponse> publishPlaza(@RequestBody AdminPublishPlazaRequest request) {
        UserProfile userProfile = LoginUserThread.get();
        AdminPublishPlazaResponse response = plazaService.publishPlaza(userProfile, request);
        return Result.success(response);
    }

    @ApiOperation("更新广场内容")
    @PutMapping("{id}")
    public Result<AdminUpdatePlazaResponse> updatePlaza(@PathVariable("id") Long id, @RequestBody AdminUpdatePlazaRequest request) {
        UserProfile userProfile = LoginUserThread.get();
        AdminUpdatePlazaResponse response = plazaService.updatePlaza(userProfile, id, request);
        return Result.success(response);
    }

    @ApiOperation("分页查询广场列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page_num", value = "页码", dataType = "number"),
            @ApiImplicitParam(name = "page_size", value = "页记录数", dataType = "number"),
    })
    @GetMapping("")
    public Result<PageResult<AdminPlazaPageListResponse>> plazaList(@RequestParam(name = "page_num", defaultValue = "1") int pageNum,
                                                                    @RequestParam(name = "page_size", defaultValue = "10") int pageSize){
        return plazaService.pageList(pageNum, pageSize);
    }

    @ApiOperation("删除广场内容")
    @DeleteMapping("{id}")
    public Result<AdminPlazaDeletedResponse> plazaDelete(@PathVariable("id") Long id){
        UserProfile userProfile = LoginUserThread.get();
        plazaService.plazaDelete(userProfile, id);
        return Result.success();
    }

    @ApiOperation("广场内容详情")
    @GetMapping("{id}")
    public Result<AdminPlazaInfoResponse> plazaDetail(@PathVariable("id") Long id){
        UserProfile userProfile = LoginUserThread.get();
        AdminPlazaInfoResponse response = plazaService.plazaDetail(userProfile, id);
        return Result.success(response);
    }

}
